#include "UdpServer.hpp"
#include <stdio.h>
#include <string>
#include <iostream>
#include <memory>

std::string ExcuteCommand(std::string command)
{
    FILE* fp = popen(command.c_str(), "r");

    std::string response;
    char buffer[1024];
    while(true)
    {
        char *s = fgets(buffer, sizeof(buffer), fp);
        if(!s) break;
        else response += buffer;
    }
    pclose(fp);
    return response.empty() ? "success" : response;
}
int main(int argc, char* argv[])
{
    uint16_t port = std::stoi(argv[1]);
    std::unique_ptr<UdpServer> usvr = std::make_unique<UdpServer>(ExcuteCommand, port);
    usvr->Init();
    usvr->Start();

}